package struts.form;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.jdom.JDOMException;

import service.vo.XMLStruts.XMLBean;



/**
 * 监听实现 ServletContextListener接口
 * @author admin
 *
 */
public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent servletcontextevent) {
		// TODO Auto-generated method stub
		System.out.println("系统信息已经注销");
	}

	@Override
	public void contextInitialized(ServletContextEvent servletcontextevent) {
		// TODO Auto-generated method stub
		ServletContext context = servletcontextevent.getServletContext();
		//获取xml的地址
		String xmlPath =context.getInitParameter("struts-config.xml");
		String  tomcatPath = context.getRealPath("\\");
		Map<String,XMLBean> map =null;
		try {
		 map =  XMLBean.excuteXML(tomcatPath+xmlPath);
		 context.setAttribute("struts", map);
		} catch (JDOMException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("系统已经加载完成");
	}

}
